package com.ruoyi.common.oneclicklogin;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.ProjectConstant;

/**
 * 	一键登录
 * @author DEREK
 *
 */
public class OneClickLoginUtil {

	/**
	 *  结果：MobileNumberGetResponse(super=CommonResponse(code=200, msg=ok), data=MobileNumberResult(phone=19953264300, resultCode=0))
		返回数据：
		{"phone":"19953264300","resultCode":"0"}
	 */

	public static String getMobile(String token,String accessToken) {
		String mobile = "";
		try {
			OneClickLoginClient oneClickLoginClient = new OneClickLoginClient(ProjectConstant.NETEASE_SECRET_ID, ProjectConstant.NETEASE_SECRET_KEY);
			MobileNumberGetRequest request = new MobileNumberGetRequest(ProjectConstant.NETEASE_BUSINESS_ID)
					.token(token)
					// 【不可重复使用】运营商授权码(有效期2分钟)
					.accessToken(accessToken);
			MobileNumberGetResponse response = null;
			response = oneClickLoginClient.getMobileNumber(request);
			System.out.println("结果："+response.toString());
			if (response != null && response.getCode() == 200) {
				MobileNumberResult data = response.getData();
				System.out.println("返回数据：");
				System.out.println(JSONObject.toJSONString(data));
				return data.getPhone();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mobile;

	}
}
